﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace ShopManagement
{
    public partial class FormCreate : Form
    {
        private readonly ShopServices service = new ShopServices();
        public FormCreate()
        {
            InitializeComponent();
        }

        private void butCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void butOk_Click(object sender, EventArgs e)
        {
            try
            {
                // 创建 ProductsCreateModel 实例
                ProductsCreateModel model = new ProductsCreateModel()
                {
                    Name = textName.Text,
                    Description = textDsb.Text,
                    Price = decimal.Parse(textPrice.Text, CultureInfo.InvariantCulture), // 确保使用正确的文化信息
                    Stock = int.Parse(textStock.Text),
                    Category=textCat.Text,
                    
                }; 
                service.Create(model);
                this.DialogResult = DialogResult.OK;
                this.Close();



            }
            catch (FormatException ex)
            {
                MessageBox.Show("输入的数值格式不正确，请检查并重新输入。", "输入错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
           ;
        }
       
    }     
}
